import Vue from 'vue'
import Router from 'vue-router'
import login from './components/login.vue'
import Home from './components/Home.vue'
import neishen from './components/neishen'
import waishen from './components/waishen'
import caiwu from './components/caiwu'
import quanxian from './components/quanxian'
import fangkuan from './components/fangkuan'
import wode from './components/wode'
import baobiao from './components/baobiao'

Vue.use(Router)

const router = new Router({
  routes: [
    { path:'/',redirect:'/login'},
    { path:'/login',component:login},
    { path:'/home',component:Home ,children:[{
        path: '/neishen',
        name: 'neishen',
        component: neishen
      }, {
        path: '/waishen',
        name: 'waishen',
        component: waishen
      }, {
        path: '/caiwu',
        name: 'caiwu',
        component: caiwu
      }, {
        path: '/quanxian',
        name: 'quanxian',
        component: quanxian
      }, {
        path: '/fangkuan',
        name: 'fangkuan',
        component: fangkuan
      }, {
        path: '/wode',
        name: 'baobiao',
        component: wode
      }, {
        path: '/baobiao',
        name: 'baobiao',
        component: baobiao
      }] },
  ]
})



router.beforeEach((to,from,next)=>{
  if(to.path=='/login') return next()
  const tokenStr = window.sessionStorage.getItem("token")
  if(!tokenStr) return next('/login')
  next()
})

export default router
